package com.xaicode.template.aop.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * @author Locker cjxia@isoftstone.com
 * @date 2021/8/3 0003 17:10
 */
@Component
@Aspect
@Slf4j
public class AccessAspect {

    @Pointcut(value = "@annotation(com.xaicode.template.aop.aspect.Access)")
    public void access() {
    }

    @Before("access()")
    public void before(JoinPoint joinPoint) {
        log.info("AccessAspect before");
    }

    @Around("@annotation(com.xaicode.template.aop.aspect.Access)")
    public Object around(ProceedingJoinPoint point) {
        log.info("AccessAspect around before");
        try {
            log.info("AccessAspect around try");
            return point.proceed();
        } catch (Throwable throwable) {
            log.info("AccessAspect around error");
            throwable.printStackTrace();
            return null;
        }
    }

}
